package com.cnap.controller;

import com.cnap.model.stage.SingleStageDeployParam;
import com.cnap.model.stage.StageDeployParam;
import com.cnap.service.DistributeDeployService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.util.Collections;

/**
 * <类文件描述>
 *
 * @author xc
 **/
class StageControllerTest extends com.cnap.CnapApplicationTests {

    @Autowired
    private StageController stageController;

    @MockBean
    private DistributeDeployService distributeDeployService;

    @Test
    void startDeploy() {
        StageDeployParam param = new StageDeployParam();
        SingleStageDeployParam singleStageDeployParam = new SingleStageDeployParam();
        singleStageDeployParam.setSvcId("1");
        param.setParams(Collections.singletonList(singleStageDeployParam));
        Mockito.doNothing().when(distributeDeployService).startDistributeDeploy(param);

        Assertions.assertDoesNotThrow(() -> {
            stageController.startDeploy(param);
        });
    }

    @Test
    void getStageByServiceId() {
        Mockito.when(distributeDeployService.getStageInfoByServiceId("svcId")).thenReturn(null);

        Assertions.assertDoesNotThrow(() -> {
            stageController.getStageByServiceId("svcId");
        });
    }

    @Test
    void getStagesByAppId() {
        Mockito.when(distributeDeployService.getStagesInfoByAppId("appId")).thenReturn(null);

        Assertions.assertDoesNotThrow(() -> {
            stageController.getStagesByAppId("appId");
        });
    }

    @Test
    void retryWithStage() {
        Mockito.doNothing().when(distributeDeployService).retryByServiceId("svcId");

        Assertions.assertDoesNotThrow(() -> {
            stageController.retryWithStage("svcId");
        });
    }
}